﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

public partial class POTextBox : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Text != null && Text.Length > 0)
                _txtPO.Text = Text;
            else
                _txtPO.Text = "";

            if (style!=null && style.Length > 0)
                _txtPO.Attributes.Add("style", style);
            if (CssClass!=null && CssClass.Length > 0)
                _txtPO.CssClass = CssClass;
            if (ToolTip!=null && ToolTip.Length > 0)
                _txtPO.ToolTip = ToolTip;
        }
    }

    public void validatePO(object source, ServerValidateEventArgs args)
    {
        bool ret = false;
        string sql = "SELECT count(1) FROM tbl_purchase_order where LOWER(PURCHASE_ORDER_NO)=@PURCHASE_ORDER_NO";
        MySqlCommand cmd = new MySqlCommand(sql);
        cmd.Parameters.AddWithValue("@PURCHASE_ORDER_NO", args.Value.ToLower());
        if (Convert.ToInt32(DBUtil.ExecuteScalar(cmd)) > 0)
            args.IsValid = true;
        else
            args.IsValid = false;
    }

    [DefaultValue("")]
    public string Text { get; set; }
    [DefaultValue("")]
    public string style { get; set; }
    [DefaultValue("")]
    public string CssClass { get; set; }
    [DefaultValue("")]
    public string ToolTip { get; set; }

}